import {Component, Input, OnInit} from '@angular/core';
import { ApiService } from '@core/services/http/api.service';
import { GridConfigService } from '@core/config/grid-config.service';
import { ApesMessageService } from '@shared/apes/message';

@Component({
  selector: 'chart',
  templateUrl: './chart.component.html',
  styleUrls: ['./chart.component.scss']
})
export class ChartComponent implements OnInit {

  name: string = 'ChartComponent';

  params: any;

  salesPieData: any;
  xinbao = [];
  xubao = [];
  xin : any =  40;
  xu : any = 30;

  mdjcTime: any[] = [];
  mdjcTime_ks = null;
  mdjcTime_js = null;

  endDate = null;      // 默认结束时间
  startDate = null;    // 默认开始时间 当天的前7天
  nowDay: any;

  button = [
    { name: '删除', bot: 'delete' }
  ];

  constructor(private apiService: ApiService,
              private gridConfigService: GridConfigService,
              private msg: ApesMessageService,) {

  }


  ngOnInit() {
    console.log("ChartComponent----> params", this.params);
    // this.endDate = new Date();
    // this.nowDay = this.endDate.toISOString().slice(8, 10);
    // this.startDate = new Date(this.endDate.getTime() - ((this.nowDay - 1 ) * 24 * 60 * 60 * 1000));
    // this.mdjcTime.push(this.startDate);
    // this.mdjcTime.push(this.endDate);
    // this.submit();

    this.salesPieData = this.getSalesTypePie();
  }

  // submit() {

    // this.xinbao = [];
    // this.xubao = [];
    // this.xin = 0;
    // this.xu = 0;
    //
    // this.getDate(this.mdjcTime, "mdjcTime_ks", "mdjcTime_js");

    // this.getTablesData();
  // }

  // getTablesData() {
  //   let data = { 'interfaceMethod': 'ipmBusinessStatementService.getXbfx', 'pdata': {
  //       'ZDRQ_SJ': this.mdjcTime_ks, 'SKRQ_SJ': this.mdjcTime_js } };
  //   this.apiService.post('report.interface', { 'body': JSON.stringify(data) }).subscribe(
  //     (resultData) => {
  //       const result = JSON.parse(resultData);
  //       if (result.success) {
  //         if (result.obj.length !== 0) {
  //           let data = JSON.parse(result.obj);
  //           data = data.sort(this.sortarr('RQ'));
  //
  //           for (let i = 0, len = data.length; i < len; i++) {
  //             this.xinbao.push(data[i].XIN);
  //             this.xubao.push(data[i].XU);
  //           }
  //           for (let i = 0, len = this.xinbao.length; i < len; i++) {
  //             this.xin += this.xinbao[i];
  //           }
  //           for (let i = 0, len = this.xubao.length; i < len; i++) {
  //             this.xu += this.xubao[i];
  //           }
  //           this.salesPieData = this.getSalesTypePie();
  //         }
  //       } else {
  //         this.msg.info(result.msg);
  //       }
  //     });
  // }

  getSalesTypePie() {
    return [
      { x: '新保数', y: this.xin },
      { x: '续保数', y: this.xu },
    ];
  }

  // getDate(time: any[], time_ks: string, time_js: string) {
  //   // debugger;
  //   let [first, second] = time;
  //   if (first) {
  //     this[time_ks] = first.toISOString().slice(0, 10);
  //   } else {
  //     this[time_ks] = null;
  //   }
  //
  //   if (second) {
  //     this[time_js] = second.toISOString().slice(0, 10);
  //   } else {
  //     this[time_js] = null;
  //   }
  //
  // }

  // sortarr(arr) {
  //   return function (obj1, obj2) {
  //     let val1 = obj1[arr];
  //     let val2 = obj2[arr];
  //     if (val1 > val2) {
  //       return 1;
  //     } else if (val1 < val2) {
  //       return -1;
  //     } else {
  //       return 0;
  //     }
  //   }
  // }
}
